# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-hypothesis
pkgver=6.72.0
pkgrel=2
pkgdesc="Advanced Quickcheck style testing library for Python"
arch=('any')
license=('MPL')
url="https://hypothesis.readthedocs.org"
depends=('python-attrs' 'python-sortedcontainers' 'python-exceptiongroup')
optdepends=('python-pytz: for datetime and django module'
            'python-faker: for fakefactory and django module'
            'python-django: for django module'
            'python-numpy: for numpy module'
            'python-pytest: for pytest module'
            'python-lark-parser: for lark module'
            'python-libcst: for codemods module')
makedepends=('python-build' 'python-installer' 'python-setuptools' 'python-wheel')
checkdepends=('python-pytest' 'flake8' 'python-pytz' 'python-numpy' 'python-faker'
              'python-flaky' 'python-django' 'python-pandas' 'python-dpcontracts'
              'python-pytest-xdist' 'python-lark-parser' 'python-pexpect' 'python-coverage'
              'python-typing_extensions' 'python-black' 'python-fakeredis' 'python-libcst')
source=("$pkgname-$pkgver.tar.gz::https://github.com/HypothesisWorks/hypothesis/archive/hypothesis-python-$pkgver.tar.gz")
sha512sums=('7d5cdf91114a34267edcca10295ee84005f2799ed58e7125c584fcc49171e60383a80c7a0040e41d24b3225113cb354966d40f61c94a28bcdbd596582577372b')

prepare() {
  mv hypothesis-hypothesis-python-$pkgver hypothesis-$pkgver
}

build() {
  cd hypothesis-$pkgver/hypothesis-python

  python -m build -nw
}

check() {
  cd hypothesis-$pkgver/hypothesis-python

  python setup.py install --root="$PWD/tmp_install" --optimize=1
  python examples/example_hypothesis_entrypoint/setup.py install --root="$PWD/tmp_install" --optimize=1

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  PYTHONPATH="$PWD/tmp_install/$site_packages:$PWD/examples/example_hypothesis_entrypoint" \
  PATH="$PWD/tmp_install/usr/bin:$PATH" \
    pytest --ignore tmp_install || echo "Tests failed"
}

package() {
  cd hypothesis-$pkgver/hypothesis-python

  python -m installer -d "$pkgdir" dist/*.whl

  # It's only present when tests are enabled, so adding -f
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  rm -rf "$pkgdir"/$site_packages/tests
}
